using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace $safeprojectname$.Tools
{
    public class LimitedQueue<T> : Queue<T>
    {
        private int? maxCapacity { get; set; }

        public LimitedQueue() { maxCapacity = null; }
        public LimitedQueue(int capacity) { maxCapacity = capacity; }

        public void Add(T newElement)
        {
            if (this.Count == (maxCapacity ?? -1)) this.Dequeue(); // no limit if maxCapacity = null
            this.Enqueue(newElement);
        }

        public string Format()
        {
            StringBuilder sb = new StringBuilder();
            foreach (var item in this)
            {
                sb.AppendLine(item.ToString());
            }

            return sb.ToString();
        }
    }
}
